package com.bilibili.movies.exception;


    //SignatureException

import io.jsonwebtoken.SignatureException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
    public class GlobalExceptionHandler {

        @ExceptionHandler(SignatureException.class)
        @ResponseBody
        public ResponseEntity<Object> handleJwtAuthenticationException(SignatureException e) {
            // 创建错误响应体
            Map<String, Object> errorDetails = new HashMap<>();
            errorDetails.put("message", e.getMessage());
            errorDetails.put("timestamp", LocalDateTime.now());

            // 设置HTTP状态码，例如401 Unauthorized
            return new ResponseEntity<>(errorDetails, HttpStatus.UNAUTHORIZED);
        }

        // 这里可以添加其他异常处理方法来处理不同类型的异常
    }
